package cn.swu.lyx.homework2

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView


class commodityFragment : Fragment() {

    val commodityList= arrayListOf<commodity>()
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_commodity_management, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initCommodity()
        val recyclerView=view.findViewById<RecyclerView>(R.id.crecyclerView)
        if (recyclerView != null) {
            recyclerView.layoutManager= LinearLayoutManager(managementSystem())
            recyclerView.adapter=CommodityAdapter(commodityList)
        }
    }

    private fun initCommodity() {
        repeat(20){
            commodityList.add(
                commodity().apply {
                    name="芝士霉霉2.0"
                    description=
                        "草莓多肉×茉莉花茶×奶盖。就近产区鲜采草莓,每杯现捣果肉,果茸丝丝;茉莉花茶与新鲜草莓搅打成沙冰,莓香四溢茶香点缀。伴随浓郁芝士奶盖,每一口都酸甜满足。"
                    image=R.drawable.zsmm2
                }
            )
        }
    }
}

